﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZOVNP.Model.Abstracts;

namespace ZOVNP.Engine
{
    [DomainObject(typeof(IPriceItem))]
    public partial class PriceItem : IPriceItem
    {
        private IDomainReference<IPrice> _priceLocker;
        private IDomainReference<IProduct> _productLocker;
        private IDomainReference<IMaterial> _materialLocker;
        private IDomainCollection<IOrderItem> _orderItemsLocker;

        public PriceItem()
        {
            _priceLocker = new SmartReference<PriceItem, Price, IPrice>(this, PriceReference, it => it.PriceID);
            _productLocker = new SmartReference<PriceItem, Product, IProduct>(this, ProductReference, it => it.ProductID);
            _materialLocker = new SmartReference<PriceItem, Material, IMaterial>(this, MaterialReference, it => it.MaterialID);
            _orderItemsLocker = new SmartCollection<OrderItem, IOrderItem>(this, OrderItems);
        }

        IDomainReference<IPrice> IPriceItem.PriceReference
        {
            get { return _priceLocker; }
        }

        IPrice IPriceItem.Price
        {
            get
            {
                return _priceLocker.Value;
            }
            set
            {
                _priceLocker.Value = value;
            }
        }

        IDomainReference<IProduct> IPriceItem.ProductReference
        {
            get { return _productLocker; }
        }

        IProduct IPriceItem.Product
        {
            get
            {
                return _productLocker.Value;
            }
            set
            {
                _productLocker.Value = value;
            }
        }

        IDomainReference<IMaterial> IPriceItem.MaterialReference
        {
            get { return _materialLocker; }
        }

        IMaterial IPriceItem.Material
        {
            get
            {
                return _materialLocker.Value;
            }
            set
            {
                _materialLocker.Value = value;
            }
        }

        IDomainCollection<IOrderItem> IPriceItem.OrderItems
        {
            get { return _orderItemsLocker; }
        }
    }
}
